package com.qingzhou.web.service.util;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.query.QueryWrapper;
import com.qingzhou.system.domain.SysDictData;
import com.qingzhou.system.service.ISysDictDataService;
import org.noear.solon.Solon;

public class DictUtil {
    public static String getLabel(String value, String parentCode){
        if(StrUtil.isEmpty(value)) return "";

        ISysDictDataService dictDataService = Solon.context().getBean(ISysDictDataService.class);
        SysDictData condition = new SysDictData();
        condition.setDictValue(value);
        condition.setDictType(parentCode);
        SysDictData dictData = dictDataService.getMapper().selectOneByQuery(QueryWrapper.create(condition));
        if(ObjUtil.isNotNull(dictData)){
            return dictData.getDictLabel();
        }
        return value;
    }

    public static SysDictData getDict(String value, String parentCode){
        if(StrUtil.isEmpty(value)) return null;

        ISysDictDataService dictDataService = Solon.context().getBean(ISysDictDataService.class);
        SysDictData condition = new SysDictData();
        condition.setDictValue(value);
        condition.setDictType(parentCode);
        return dictDataService.getMapper().selectOneByQuery(QueryWrapper.create(condition));
    }
}
